﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using logic;
using System.Data;
using System.Data.SqlClient;

namespace PeisongWeb.admin
{
    public partial class buyerPriceWeekList:adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("KB", 1))
                {
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }

        private void drpBind()
        {
            DataTable dt = logic.company.listWithWeeklyPrice();
            ddlCompany.DataSource = dt;
            ddlCompany.DataBind();
        }

        private void rptBind()
        {
            int companyId = 0;
            int.TryParse(ddlCompany.SelectedValue, out companyId);

            string year = ddlYear.SelectedValue;
            DataTable dt = logic.purchaseWeek.listWithCompanyAndYear(companyId, int.Parse(year));
            rpt_list.DataSource = dt;
            rpt_list.DataBind();
        }

        // 初始化企业周报价体系
        protected void btnInitWeeklyPrice_Click(object sender, EventArgs e)
        {
            int companyId = 0;
            int.TryParse(ddlCompany.SelectedValue, out companyId);

            string year = ddlYear.SelectedValue;

            int createAdminId=logic.sysAdmin.AdminID;

            bool initStatus=logic.purchaseWeek.insert(companyId, int.Parse(year), createAdminId);

            if (initStatus)
            {
                Library.Script.ClientMsg("企业周报价体系初始化成功.");
            }
            else
            {
                Library.Script.ClientMsg("企业周报价体系初始化失败,该企业已初始化周报价体系.");
            }

            rptBind();
            
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
